package com.tsystems.entities;

import java.io.Serializable;
import java.util.List;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;


@Entity
public class Station implements Serializable {


	private static final long serialVersionUID = -5145756097598092716L;
	
	@Id
	private String id;
	
	@PrePersist
	public void prepareId() {
		if (id == null) {
			id = UUID.randomUUID().toString();
		}
	}
	
	@NotNull(message="Наименование станции должно быть задано.")
	@Size( max=20, message= "Наименование станции должно быть меньше 20 символов.")
	@Column(unique = true,  nullable = false, length = 20)
	private String name;
	
	@OneToMany(mappedBy = "arrivalStation")
	private List<TimeTableElement> arrivalTimeTableElements;
	
	@OneToMany(mappedBy = "departureStation")
	private List<TimeTableElement> departureTimeTableElements;
	
	public Station() {

	}
	
	




	public Station(String name) {
		super();
		this.name=name;
		
	}
	
	
	public String getId() {
		return id;
	}



	public void setId(String id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<TimeTableElement> getArrivalTimeTableElements() {
		return arrivalTimeTableElements;
	}

	public void setArrivalTimeTableElements(
			List<TimeTableElement> arrivalTimeTableElements) {
		this.arrivalTimeTableElements = arrivalTimeTableElements;
	}

	public List<TimeTableElement> getDepartureTimeTableElements() {
		return departureTimeTableElements;
	}

	public void setDepartureTimeTableElements(
			List<TimeTableElement> departureTimeTableElements) {
		this.departureTimeTableElements = departureTimeTableElements;
	}

	@Override
	public String toString() {
		return name;
	}

}
